package notepad;


import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
//import java.awt.event.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
//import java.awt.event.KeyEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.text.SimpleDateFormat;
import java.time.Clock;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import java.util.Calendar;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.border.BevelBorder;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener;
import javax.swing.event.UndoableEditEvent;
import javax.swing.event.UndoableEditListener;
import javax.swing.undo.CannotUndoException;
//import javax.swing.KeyStroke;
import javax.swing.undo.UndoManager;
import javax.xml.crypto.Data;

public class Window extends JFrame implements ActionListener,DocumentListener {
	JFrame jf,frame;
	JMenuBar bar;
	JToolBar toolBar;
	//菜单条菜单
	JMenu fileMenu, editMenu,formatMenu,viewMenu,helpMenu,zoomMenu;
	//“文件”菜单项
	JMenuItem newItem, openItem, saveItem, saveAsItem,closeItem,setUpItem,printItem;
	//“编辑”菜单项
	JMenuItem undoItem,cutItem,copyItem,pasteItem,deleteItem,findItem,findNextItem,replaceItem,goItem,allItem,dateItem;
	//“格式”菜单项
	JCheckBoxMenuItem wrapItem;
	JMenuItem fontItem;
	//“查看”菜单项
	JMenuItem bigItem,smallItem,defaultItem;
	JCheckBoxMenuItem statusItem;
	//"帮助"菜单项
	JMenuItem askHelpItem,feedbackItem,aboutItem;
	//图标
	ImageIcon newIcon, openIcon, saveIcon, saveAsIcon,closeIcon,setUpIcon,printIcon;
	//“文本编辑区域”
	//右键点击弹出菜单
	JPopupMenu popupMenu;
	//弹出菜单的菜单项
	JMenuItem popupUndoItem,popupCutItem,popupCopyItem,popupPasteItem,popupDeleteItem,popupAllItem;
	//状态栏标签
	JLabel statusLabel;
	JPanel statusPanel;
	  private JLabel label = null;
	    private JLabel labelTime = null;
	    private JLabel labelCodeStyle = null;
	//系统剪贴板  
    Toolkit toolkit=Toolkit.getDefaultToolkit();  
    Clipboard clipBoard=toolkit.getSystemClipboard();  
    //创建撤销操作管理器(与撤销操作有关)  
    protected UndoManager undo=new UndoManager();  
    //protected UndoableEditListener undoHandler=new UndoHandler();
	JTextArea area;
	JScrollPane scroll;
	int c,line,col,length;
	JFileChooser chooser;
	File file;
	FileInputStream fis;
	FileOutputStream fos;
	private String form;// 字体
	private int font;// 字形
	private int size;// 字体大小
	private String oldValue;
	private UndoableEditListener undoHandler;
 
	public Window() {
		newWindow();
 
		//MyTool tool = new MyTool();
		//tool.setJFrameImage(jf);
		jf.setSize(1000, 800);
		
		//tool.setJFrameLcotionCenter(jf);
		jf.setVisible(true);
		
		form = "宋体";
		font = Font.ITALIC;
		size = 14;
	}
 
	//@SuppressWarnings("deprecation")
	@SuppressWarnings("deprecation")
	public void newWindow() {
		jf = new JFrame("记事本");
		form = "宋体";
		font = Font.ITALIC;
		size = 14;
		
		bar = new JMenuBar(); // new一个菜单条
 
		fileMenu = new JMenu("文件(F)"); // 菜单栏里面的文件菜单
		fileMenu.setMnemonic('F');//设置快捷键ALT+F 
		newIcon = new ImageIcon("img\\new.png"); // 文件菜单里的四个图标
		openIcon = new ImageIcon("img\\open.png");
		saveIcon = new ImageIcon("img\\save.png");
		saveAsIcon = new ImageIcon("img\\saveAs.png");
		setUpIcon = new ImageIcon("img\\setUp.png");
		printIcon = new ImageIcon("img\\print.png");
		closeIcon = new ImageIcon("img\\close.png");
 
		newItem = new JMenuItem("新建（N）", newIcon); // 文件菜单里的菜单项
		newItem.setMnemonic(KeyEvent.VK_N); //添加快捷方式         
		newItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, Event.CTRL_MASK));// Accelerator快捷键
		newItem.addActionListener(this);// 添加监听器
		
		openItem = new JMenuItem("打开（O）", openIcon);
		openItem.setMnemonic(KeyEvent.VK_O);
		openItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, Event.CTRL_MASK));
		openItem.addActionListener(this);
		
		saveItem = new JMenuItem("保存（S）", saveIcon);
		saveItem.setMnemonic(KeyEvent.VK_S);
		saveItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.CTRL_MASK));
		saveItem.addActionListener(this);
		
		saveAsItem = new JMenuItem("另存为（A）",saveAsIcon);
		saveAsItem.setMnemonic(KeyEvent.VK_A);
		saveAsItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A,Event.CTRL_MASK));
		saveAsItem.addActionListener(this);
		
		setUpItem = new JMenuItem("页面设置（U）",setUpIcon);
		setUpItem.addActionListener(this);
		
		printItem = new JMenuItem("打印（P）",printIcon);
		printItem.setMnemonic(KeyEvent.VK_P);
		printItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, Event.CTRL_MASK));
		printItem.addActionListener(this);
		
		closeItem = new JMenuItem("关闭（X）", closeIcon);
		closeItem.setMnemonic(KeyEvent.VK_X);
		closeItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, Event.CTRL_MASK));
		closeItem.addActionListener(this);
		
		
		
		
		
		editMenu = new JMenu("编辑(E)"); //编辑菜单
		editMenu.setMnemonic('E');//设置快捷键ALT+E
		 //当选择编辑菜单时，设置剪切、复制、粘贴、删除等功能的可用性  
        editMenu.addMenuListener(new MenuListener()  
        {   public void menuCanceled(MenuEvent e)//取消菜单时调用  
            {   checkMenuItemEnabled();//设置剪切、复制、粘贴、删除等功能的可用性  
            }  
         //   private void checkMenuItemEnabled() {
			// TODO 自动生成的方法存根
			
		//}
			public void menuDeselected(MenuEvent e)//取消选择某个菜单时调用  
            {   checkMenuItemEnabled();//设置剪切、复制、粘贴、删除等功能的可用性  
            }  
            public void menuSelected(MenuEvent e)//选择某个菜单时调用  
            {   checkMenuItemEnabled();//设置剪切、复制、粘贴、删除等功能的可用性  
            }  
        });  
        
        undoItem = new JMenuItem("撤消（U）"); //编辑菜单里的菜单项
		undoItem.setMnemonic(KeyEvent.VK_Z);
		undoItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, InputEvent.CTRL_MASK));
		undoItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (undo.canUndo()) {// 如果可以撤销
					undo.undo();// 撤销
				}
			}
		});
		
		
		cutItem = new JMenuItem("剪切（T）");
		cutItem.setMnemonic(KeyEvent.VK_X);
		cutItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK));
		cutItem.addActionListener(this);
		
		copyItem = new JMenuItem("复制（C）");
		copyItem.setMnemonic(KeyEvent.VK_C);
		copyItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK));
		copyItem.addActionListener(this);
		
		pasteItem = new JMenuItem("粘贴（V）");
		pasteItem.setMnemonic(KeyEvent.VK_V);
		pasteItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK));
		pasteItem.addActionListener(this);
		
		deleteItem = new JMenuItem("删除（DEL）");
		deleteItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE,0));  
		deleteItem.addActionListener(this);
		
		findItem = new JMenuItem("查找（F）...");
		findItem.setMnemonic(KeyEvent.VK_F);
		findItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_MASK));
		findItem.addActionListener(this);
		
		findNextItem=new JMenuItem("查找下一个(N)");  
        findNextItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F3,0));  
        findNextItem.addActionListener(this);  
		
		replaceItem = new JMenuItem("替换（R）...");
		replaceItem.setMnemonic(KeyEvent.VK_H);
		replaceItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H, InputEvent.CTRL_MASK));
		replaceItem.addActionListener(this);
		
		goItem = new JMenuItem("转到（G）");
		goItem.setMnemonic(KeyEvent.VK_G);
		goItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G, InputEvent.CTRL_MASK));
		goItem.addActionListener(this);
		
		allItem = new JMenuItem("全选（A）");
		allItem.setMnemonic(KeyEvent.VK_A);
		allItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_MASK));
		allItem.addActionListener(this);
		
		dateItem = new JMenuItem("时间/日期（D）");
		dateItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5,0));
		dateItem.addActionListener(this);
        
        
        
		formatMenu = new JMenu("格式(O)"); //格式菜单
		formatMenu.setMnemonic('O');//设置快捷键ALT+O 
		
		wrapItem = new JCheckBoxMenuItem("自动换行（W）"); //格式菜单里的菜单项
		wrapItem.setMnemonic('W');//设置快捷键ALT+W 
		wrapItem.addActionListener(this);
		wrapItem.setState(true);
		fontItem = new JMenuItem("字体（F）");
		fontItem.addActionListener(this);
		
		viewMenu = new JMenu("查看(V)");  //查看菜单
		viewMenu.setMnemonic('V');//设置快捷键ALT+V 
		zoomMenu = new JMenu("缩放(Z)");
		zoomMenu.setMnemonic('Z');//设置快捷键ALT+Z 
		bigItem = new JMenuItem("放大（I）");    //查看菜单里的菜单项
		bigItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, KeyEvent.CTRL_MASK));
		bigItem.addActionListener(this);
		smallItem = new JMenuItem("缩小（O）");
		smallItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, KeyEvent.CTRL_MASK));
		smallItem.addActionListener(this);
		defaultItem =new JMenuItem("恢复默认状态");
		defaultItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_0, KeyEvent.CTRL_MASK));
		defaultItem.addActionListener(this);
		statusItem = new JCheckBoxMenuItem("状态栏（S）");
		statusItem.setMnemonic('S');
		statusItem.setState(true);
		statusItem.addActionListener(this);
		
		
		helpMenu = new JMenu("帮助(H)");
		helpMenu.setMnemonic('H');//设置快捷键ALT+H
		
		askHelpItem = new JMenuItem("查看帮助（H）"); //帮助菜单里的菜单项
		askHelpItem.addActionListener(this); 
		feedbackItem = new JMenuItem("发送回馈（F）");
		feedbackItem.addActionListener(this);
		aboutItem = new JMenuItem("关于记事本（A）");
		aboutItem.addActionListener(this);
		
		
		jf.setJMenuBar(bar);
 
		bar.add(fileMenu);          //添加菜单条
		bar.add(editMenu);
		bar.add(formatMenu);
		bar.add(viewMenu);
		bar.add(helpMenu);
 
		fileMenu.add(newItem);     //添加文件菜单里的菜单项
		fileMenu.add(openItem);
		fileMenu.add(saveItem);
		fileMenu.add(saveAsItem);
		fileMenu.addSeparator();
		fileMenu.add(setUpItem);
		fileMenu.add(printItem);
		fileMenu.addSeparator();
		fileMenu.add(closeItem);
		
		editMenu.add(undoItem);    //添加编辑菜单里的菜单项
		editMenu.addSeparator();
		editMenu.add(cutItem);
		editMenu.add(copyItem);
		editMenu.add(pasteItem);
		editMenu.add(deleteItem);
		editMenu.addSeparator();
		editMenu.add(findItem);
		editMenu.add(findNextItem);
		editMenu.add(replaceItem);
		editMenu.add(goItem);
		editMenu.addSeparator();
		editMenu.add(allItem);
		editMenu.add(dateItem);

		
		formatMenu.add(wrapItem);
		formatMenu.add(fontItem);
		
		viewMenu.add(zoomMenu);
		viewMenu.add(statusItem);
		
		zoomMenu.add(bigItem);
		zoomMenu.add(smallItem);
		zoomMenu.add(defaultItem);
		
		helpMenu.add(askHelpItem);
		helpMenu.add(feedbackItem);
		helpMenu.addSeparator();
		helpMenu.add(aboutItem);
 
		
		 area = new JTextArea(20,50); // new多行文本框
			scroll = new JScrollPane(area); // 用构造方法在面板中加入多行文本框
			scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);// Vertical垂直
			scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);// Horizontal 水平
			  area.setWrapStyleWord(true);
			  area.setLineWrap(true);
					oldValue = area.getText();//获取原文本编辑区的内容
					
			
	 
			chooser = new JFileChooser();// Chooser 选择器
		jf.add(scroll);
		
		
		
        //创建右键弹出菜单
        popupMenu = new JPopupMenu();
        popupUndoItem = new JMenuItem("撤消（U）");
        popupCutItem = new JMenuItem("剪切（T）");
        popupCopyItem = new JMenuItem("复制（C）");
        popupPasteItem = new JMenuItem("粘贴（P）");
        popupDeleteItem = new JMenuItem("删除（D）");
        popupAllItem = new JMenuItem("全选（A）");
        //popupUndoItem.setEnabled(false); 
        
        //文本编辑区注册右键菜单添加监听器
        popupUndoItem.addActionListener(this);
        popupCutItem.addActionListener(this);  
        popupCopyItem.addActionListener(this);  
        popupPasteItem.addActionListener(this);  
        popupDeleteItem.addActionListener(this);  
        popupAllItem.addActionListener(this); 
        
        area.add(popupMenu);
        //向右键菜单添加菜单项和分隔符  
        popupMenu.add(popupUndoItem);  
        popupMenu.addSeparator();  
        popupMenu.add(popupCutItem);  
        popupMenu.add(popupCopyItem);  
        popupMenu.add(popupPasteItem);  
        popupMenu.add(popupDeleteItem);  
        popupMenu.addSeparator();  
        popupMenu.add(popupAllItem); 
        
        
       
        
        //编辑区注册时间监听
		area.getDocument().addUndoableEditListener(undoHandler);
		area.getDocument().addDocumentListener(this);
		
        
       
        //文本编辑区注册右键菜单事件
        area.addMouseListener(new MouseAdapter() {
        	public void mousePressed(MouseEvent e) 
        	{	if(e.isPopupTrigger()) {                     //返回此鼠标事件是否为该平台的弹出菜单触发事件
        		   popupMenu.show(e.getComponent(),e.getX(),e.getY());//在组件调用者的坐标空间中的位置 X、Y 显示弹出菜单  
                }  
                checkMenuItemEnabled();//设置剪切，复制，粘帖，删除等功能的可用性  
                area.requestFocus();//编辑区获取焦点
                
            }  
            public void mouseReleased(MouseEvent e)  
            {   if(e.isPopupTrigger()) {                       //返回此鼠标事件是否为该平台的弹出菜单触发事件  
                   popupMenu.show(e.getComponent(),e.getX(),e.getY());//在组件调用者的坐标空间中的位置 X、Y 显示弹出菜单  
                }  
                checkMenuItemEnabled();//设置剪切，复制，粘帖，删除等功能的可用性  
                area.requestFocus();//编辑区获取焦点  
            }	
           
    			
    		});
        //文本编辑区注册右键菜单事件结束
        
        
        addWindowListener(new WindowAdapter()  
        {   public void windowClosing(WindowEvent e)  
        {   exitWindowChoose();  
        }

		private void exitWindowChoose() {
			
			
		}  
        });
	checkMenuItemEnabled();
	   area.requestFocus();
	   
	   undo = new UndoManager();// 创建撤销管理器
	   area.getDocument().addUndoableEditListener(undo);// 为文本注册监听器

     
	    //创建和添加状态栏
        /*JPanel statusPanel=new JPanel();
        statusPanel.setBorder(new BevelBorder(BevelBorder.LOWERED));
        jf.add(statusPanel,BorderLayout.SOUTH);
        statusPanel.setPreferredSize(new Dimension(jf.getWidth(),26));
        statusPanel.setLayout(new BoxLayout(statusPanel,BoxLayout.Y_AXIS));*/
        
        JToolBar toolBar=new JToolBar();
        jf.add(toolBar,BorderLayout.SOUTH);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        labelTime=new JLabel("    当前时间: "+sdf.format(new Date()));
        new Timer().scheduleAtFixedRate(new TimerTask() {//每一秒更新一次
        	public void run() {
        	labelTime.setText("    当前时间:" + sdf.format(new Date()));
        	}
        	}, new Date(), 1000);

        toolBar.add(labelTime);
        toolBar.addSeparator(new Dimension(200,5));
        
        
        label = new JLabel("    第 " + line + " 行, 第 " + (col+1)+" 列  ");
        toolBar.add(label);
        toolBar.addSeparator(new Dimension(150,5));
        statusLabel=new JLabel("一共"+length+"字");
        toolBar.add(statusLabel);
        toolBar.addSeparator(new Dimension(150,5));
	   //statusPanel.add(toolBar,BorderLayout.SOUTH);
	   
	   area.addCaretListener(new CaretListener() {
		   public void caretUpdate(CaretEvent e) {
               //sum=0;
               
               try {
            	  int caretpos = area.getCaretPosition();
            	  line = area.getLineOfOffset(caretpos);
            	  col = caretpos - area.getLineStartOffset(line);
            	  line += 1;
                  label.setText("    第 " + line + " 行, 第 " + (col+1)+" 列  ");
                  length=Window.this.area.getText().toString().length();
                  statusLabel.setText("    一共 " +length+" 字  ");
                  } 
                  catch(Exception ex) { }
		   }
                 
	   });
	   
	   labelCodeStyle = new JLabel("字符编码: UFT-8");
	   //labelCodeStyle.setHorizontalAlignment(JLabel.RIGHT);
	   
	   toolBar.add(labelCodeStyle);
	   toolBar.addSeparator(new Dimension(150,5));
	   
	   
	   /*----------------状态栏-----------------------
       toolBar = new JToolBar();
       toolBar.setFloatable(false);

       SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

       label = new JLabel("当前字数:0",SwingConstants.CENTER);
       labelTime = new JLabel("日期: "+sdf.format(new Date()));
       labelCodeStyle = new JLabel("编码: ");

       toolBar.add(label);
       toolBar.addSeparator(new Dimension(180,5));
       toolBar.add(labelTime);
       toolBar.addSeparator(new Dimension(180,5));
       toolBar.add(labelCodeStyle);*/
       
   
	
	
	   
	}   
	   
        

	   	
		
	
	
	
	


	
	
		//设置菜单项的可用性：剪切，复制，粘帖，删除功能 
        public void checkMenuItemEnabled() {
        	String selectText=area.getSelectedText();
        	if(selectText==null) { 
            cutItem.setEnabled(false);  
            popupCutItem.setEnabled(false);  
            copyItem.setEnabled(false);  
            popupCopyItem.setEnabled(false);  
            deleteItem.setEnabled(false);  
            popupDeleteItem.setEnabled(false);  
        }  
        else { 
            cutItem.setEnabled(true);  
            popupCutItem.setEnabled(true);   
            copyItem.setEnabled(true);  
            popupCopyItem.setEnabled(true);  
            deleteItem.setEnabled(true);  
            popupDeleteItem.setEnabled(true);  
        }
        //粘帖功能可用性判断  
        Transferable contents=clipBoard.getContents(this);  
        if(contents==null) { 
            pasteItem.setEnabled(false);  
            popupPasteItem.setEnabled(false);  
            
        }  
        else { 
            pasteItem.setEnabled(true);  
            popupPasteItem.setEnabled(true);
           
        }  
    //方法checkMenuItemEnabled()结束  
	}
        //查找方法
        public void find() {
  
        	final JDialog findDialog=new JDialog(this,"查找",false);
        	Container con=findDialog.getContentPane();
        	con.setLayout(new FlowLayout(FlowLayout.LEFT));
        	JLabel findContentLabel=new JLabel("查找内容（N）:");
        	final JTextField findText=new JTextField(15);
        	JButton findNextButton=new JButton("查找下一个（F）:");
        	final JCheckBox matchCheckBox=new JCheckBox("区分大小写（C）");
        	ButtonGroup bGroup=new ButtonGroup();
        	final JRadioButton upButton=new JRadioButton("向上（U）");
        	final JRadioButton downButton=new JRadioButton("向下（U）");
        	downButton.setSelected(true);
        	bGroup.add(upButton);
        	bGroup.add(downButton);
        	JButton cancel=new JButton("取消");
        	//取消按钮事件处理
        	cancel.addActionListener(new ActionListener() {
        		public void actionPerformed(ActionEvent e) {
        			findDialog.dispose();
        		}
        	});
        	//查找下一个按钮监听
        	findNextButton.addActionListener(new ActionListener() {
        		public void actionPerformed(ActionEvent e) {
        			int k=0,m=0;
        			final String str1,str2,str3,str4,strA,strB;
        			str1=area.getText();
        			str2=findText.getText();
        			str3=str1.toUpperCase();
        			str4=str2.toUpperCase();
        			if(matchCheckBox.isSelected()) {
        				strA=str1;
        				strB=str2;
        			}
        			else {
        				strA=str3;
        				strB=str4;
        			}
        			if(upButton.isSelected()) {
        				if(area.getSelectedText()==null)
        					k=strA.lastIndexOf(strB,area.getCaretPosition()-1);
        				else
        					k=strA.lastIndexOf(strB,area.getCaretPosition()-findText.getText().length()-1);
        				if(k>-1) {
        					area.setCaretPosition(k);
        					area.select(k,k+strB.length());
        				}
        				else {
        					JOptionPane.showMessageDialog(null, "找不到您查找的内容！","查找",JOptionPane.INFORMATION_MESSAGE);
        				}	
        			}
        			else if(downButton.isSelected()) {
        				if(area.getSelectedText()==null)
        					k=strA.indexOf(strB,area.getCaretPosition()+1);
        				else
        					k=strA.indexOf(strB,area.getCaretPosition()-findText.getText().length()+1);
        				if(k>-1) {
        					area.setCaretPosition(k);
        					area.select(k,k+strB.length());
        				}
        				else {
        					JOptionPane.showMessageDialog(null,"找不到您查找的内容！","查找",JOptionPane.INFORMATION_MESSAGE);
        				}
        			}
        		}
        	}) ;
        	
        	
        	
        	//创建对话框
        	JPanel panel1=new JPanel();
        	JPanel panel2=new JPanel();
        	JPanel panel3=new JPanel();
        	JPanel directionPanel=new JPanel();
        	directionPanel.setBorder(BorderFactory.createTitledBorder("方向"));
        	directionPanel.add(upButton);
        	directionPanel.add(downButton);
        	panel1.setLayout(new GridLayout(2,1));
        	panel1.add(findNextButton);
        	panel1.add(cancel);
        	panel2.add(findContentLabel);
        	panel2.add(findText);
        	panel2.add(panel1);
        	panel3.add(matchCheckBox);
        	panel3.add(directionPanel);
        	con.add(panel2);
        	con.add(panel3);
        	findDialog.setSize(410, 180);
        	findDialog.setResizable(false);
        	findDialog.setLocation(230, 280);
        	findDialog.setVisible(true);
        }
        
        //替换方法
        public void replace() {
        	final JDialog replaceDialog=new JDialog(this,"替换",false);
        	Container con=replaceDialog.getContentPane();
        	con.setLayout(new FlowLayout(FlowLayout.CENTER));
        	JLabel findContentLabel=new JLabel("查找内容（N）:");
        	final JTextField findText=new JTextField(15);
        	JButton findNextButton=new JButton("查找下一个（F）:");
        	JLabel replaceLabel=new JLabel("替换为（P）:");
        	final JTextField replaceText=new JTextField(15);
        	JButton replaceButton=new JButton("替换(R)");
        	JButton replaceAllButton=new JButton("全部替换（A）");
        	JButton cancel=new JButton("取消");
        	cancel.addActionListener(new ActionListener() { 
        		public void actionPerformed(ActionEvent e) {
        			replaceDialog.dispose();
        		}
        	});
        	final JCheckBox matchCheckBox=new JCheckBox("区分大小写(C)");  
            ButtonGroup bGroup=new ButtonGroup();  
            final JRadioButton upButton=new JRadioButton("向上(U)");  
            final JRadioButton downButton=new JRadioButton("向下(U)");  
            downButton.setSelected(true);  
            bGroup.add(upButton);  
            bGroup.add(downButton);  
            
            //查找下一个按钮监听
            findNextButton.addActionListener(new ActionListener() {
            	public void actionPerformed(ActionEvent e) {
            		int k=0,m=0;
        			final String str1,str2,str3,str4,strA,strB;
        			str1=area.getText();
        			str2=findText.getText();
        			str3=str1.toUpperCase();
        			str4=str2.toUpperCase();
        			if(matchCheckBox.isSelected()) {
        				strA=str1;
        				strB=str2;
        			}
        			else {
        				strA=str3;
        				strB=str4;
        			}
        			if(upButton.isSelected()) {
        				if(area.getSelectedText()==null)
        					k=strA.lastIndexOf(strB,area.getCaretPosition()-1);
        				else
        					k=strA.lastIndexOf(strB,area.getCaretPosition()-findText.getText().length()-1);
        				if(k>-1) {
        					area.setCaretPosition(k);
        					area.select(k,k+strB.length());
        				}
        				else {
        					JOptionPane.showMessageDialog(null, "找不到您查找的内容！","查找",JOptionPane.INFORMATION_MESSAGE);
        				}	
        			}
        			else if(downButton.isSelected()) {
        				if(area.getSelectedText()==null)
        					k=strA.indexOf(strB,area.getCaretPosition()+1);
        				else
        					k=strA.indexOf(strB,area.getCaretPosition()-findText.getText().length()+1);
        				if(k>-1) {
        					area.setCaretPosition(k);
        					area.select(k,k+strB.length());
        				}
        				else {
        					JOptionPane.showMessageDialog(null,"找不到您查找的内容！","查找",JOptionPane.INFORMATION_MESSAGE);
        				}
        			}
        		}
        	}) ;
        
        
        //替换按钮监听
        replaceButton.addActionListener(new ActionListener() {
        	public void actionPerformed(ActionEvent e) {
        		if(replaceText.getText().length()==0 && area.getSelectedText()!=null)
        			area.replaceSelection("");
        		if(replaceText.getText().length()>0 && area.getSelectedText()!=null)
        			area.replaceSelection(replaceText.getText());
        	}
        });
        
        //全部替换按钮监听
        replaceAllButton.addActionListener(new ActionListener() {
        	public void actionPerformed(ActionEvent e) {
        		area.setCaretPosition(0);
        		int k=0;int m=0;int replaceCount = 0;
        		 if(findText.getText().length()==0)  
                 {   JOptionPane.showMessageDialog(replaceDialog,"请填写查找内容!","提示",JOptionPane.WARNING_MESSAGE);  
                     findText.requestFocus(true);  
                     return;  
                 }  
        		 while(k>-1) {
        			 final String str1,str2,str3,str4,strA,strB;  
                     str1=area.getText();  
                     str2=findText.getText();  
                     str3=str1.toUpperCase();  
                     str4=str2.toUpperCase();  
                     if(matchCheckBox.isSelected())
                     {   strA=str1;  
                         strB=str2;  
                     }  
                     else  
                     {   strA=str3;  
                         strB=str4;  
                     }  
                     if(upButton.isSelected())  
                     {   //k=strA.lastIndexOf(strB,editArea.getCaretPosition()-1);  
                         if(area.getSelectedText()==null)  
                             k=strA.lastIndexOf(strB,area.getCaretPosition()-1);  
                         else  
                             k=strA.lastIndexOf(strB, area.getCaretPosition()-findText.getText().length()-1);      
                         if(k>-1)  
                         {   //String strData=strA.subString(k,strB.getText().length()+1);  
                             area.setCaretPosition(k);  
                             area.select(k,k+strB.length());  
                         }  
                         else  
                         {   if(replaceCount==0)  
                             {   JOptionPane.showMessageDialog(replaceDialog, "找不到您查找的内容!", "记事本",JOptionPane.INFORMATION_MESSAGE);   
                             }  
                             else  
                             {   JOptionPane.showMessageDialog(replaceDialog,"成功替换"+replaceCount+"个匹配内容!","替换成功",JOptionPane.INFORMATION_MESSAGE);  
                             }  
                         }  
                     }  
                     else if(downButton.isSelected())  
                     {   if(area.getSelectedText()==null)  
                             k=strA.indexOf(strB,area.getCaretPosition()+1);  
                         else  
                             k=strA.indexOf(strB, area.getCaretPosition()-findText.getText().length()+1);      
                         if(k>-1)  
                         {   //String strData=strA.subString(k,strB.getText().length()+1);  
                             area.setCaretPosition(k);  
                             area.select(k,k+strB.length());  
                         }  
                         else  
                         {   if(replaceCount==0)  
                             {   JOptionPane.showMessageDialog(replaceDialog, "找不到您查找的内容!", "记事本",JOptionPane.INFORMATION_MESSAGE);   
                             }  
                             else  
                             {   JOptionPane.showMessageDialog(replaceDialog,"成功替换"+replaceCount+"个匹配内容!","替换成功",JOptionPane.INFORMATION_MESSAGE);  
                             }  
                         }  
                     }  
                     if(replaceText.getText().length()==0 && area.getSelectedText()!= null)  
                     {   area.replaceSelection("");  
                         replaceCount++;  
                     }   
                       
                     if(replaceText.getText().length()>0 && area.getSelectedText()!= null)   
                     {   area.replaceSelection(replaceText.getText());   
                         replaceCount++;  
                     }  
        		 }
        	}
        });
        
        
        //创建替换对话框
        JPanel directionPanel=new JPanel();
        directionPanel.setBorder(BorderFactory.createTitledBorder("方向"));
        directionPanel.add(upButton);  
        directionPanel.add(downButton);  
        JPanel panel1=new JPanel();  
        JPanel panel2=new JPanel();  
        JPanel panel3=new JPanel();  
        JPanel panel4=new JPanel();  
        panel4.setLayout(new GridLayout(2,1));  
        panel1.add(findContentLabel);  
        panel1.add(findText);  
        panel1.add(findNextButton);  
        panel4.add(replaceButton);  
        panel4.add(replaceAllButton);  
        panel2.add(replaceLabel);  
        panel2.add(replaceText);  
        panel2.add(panel4);  
        panel3.add(matchCheckBox);  
        panel3.add(directionPanel);  
        panel3.add(cancel);  
        con.add(panel1);  
        con.add(panel2);  
        con.add(panel3);  
        replaceDialog.setSize(420,220);  
        replaceDialog.setResizable(false);//不可调整大小  
        replaceDialog.setLocation(230,280);  
        replaceDialog.setVisible(true); 
	}
        
        
        
        
        //字体方法
        public void font()  
        {   final JDialog fontDialog=new JDialog(this,"字体设置",false);  
            Container con=fontDialog.getContentPane();  
            con.setLayout(new FlowLayout(FlowLayout.LEFT));  
            JLabel fontLabel=new JLabel("字体(F)：");  
            fontLabel.setPreferredSize(new Dimension(170,20));
            JLabel styleLabel=new JLabel("字形(Y)：");  
            styleLabel.setPreferredSize(new Dimension(170,20));  
            JLabel sizeLabel=new JLabel("大小(S)：");  
            sizeLabel.setPreferredSize(new Dimension(170,20));  
            final JLabel sample=new JLabel("吴老师yyds");  
            sample.setPreferredSize(new Dimension(170,60));
            final JTextField fontText=new JTextField(17);  
            fontText.setPreferredSize(new Dimension(150,25));  
            final JTextField styleText=new JTextField(14);  
            styleText.setPreferredSize(new Dimension(150,25));  
            final int style[]={Font.PLAIN,Font.BOLD,Font.ITALIC,Font.BOLD+Font.ITALIC};  
            final JTextField sizeText=new JTextField(15);  
            sizeText.setPreferredSize(new Dimension(150,25));  
            JButton okButton=new JButton("确定");  
            JButton cancel=new JButton("取消");  
            cancel.addActionListener(new ActionListener()  
            {   public void actionPerformed(ActionEvent e)  
                {   fontDialog.dispose();     
                }  
            });  
            Font currentFont=area.getFont();  
            fontText.setText(currentFont.getFontName());  
            fontText.selectAll();  
            //styleText.setText(currentFont.getStyle());  
            //styleText.selectAll();  
            if(currentFont.getStyle()==Font.PLAIN)  
                styleText.setText("常规");  
            else if(currentFont.getStyle()==Font.BOLD)  
                styleText.setText("粗体");  
            else if(currentFont.getStyle()==Font.ITALIC)  
                styleText.setText("斜体");  
            else if(currentFont.getStyle()==(Font.BOLD+Font.ITALIC))  
                styleText.setText("粗斜体");  
            styleText.selectAll();  
            String str=String.valueOf(currentFont.getSize());  
            sizeText.setText(str);  
            sizeText.selectAll();  
            final JList fontList,styleList,sizeList;  
            GraphicsEnvironment ge=GraphicsEnvironment.getLocalGraphicsEnvironment();  
            final String fontName[]=ge.getAvailableFontFamilyNames();  
            fontList=new JList(fontName);  
            fontList.setFixedCellWidth(156);  
            fontList.setFixedCellHeight(20);  
            fontList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);  
            final String fontStyle[]={"常规","粗体","斜体","粗斜体"};  
            styleList=new JList(fontStyle);  
            styleList.setFixedCellWidth(136);  
            styleList.setFixedCellHeight(20);  
            styleList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);  
            if(currentFont.getStyle()==Font.PLAIN)  
                styleList.setSelectedIndex(0);  
            else if(currentFont.getStyle()==Font.BOLD)  
                styleList.setSelectedIndex(1);  
            else if(currentFont.getStyle()==Font.ITALIC)  
                styleList.setSelectedIndex(2);  
            else if(currentFont.getStyle()==(Font.BOLD+Font.ITALIC))  
                styleList.setSelectedIndex(3);  
            final String fontSize[]={"8","9","10","11","12","14","16","18","20","22","24","26","28","36","48","72"};  
            sizeList=new JList(fontSize);  
            sizeList.setFixedCellWidth(136);  
            sizeList.setFixedCellHeight(20);  
            sizeList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);  
            fontList.addListSelectionListener(new ListSelectionListener()  
            {   public void valueChanged(ListSelectionEvent event)  
                {   fontText.setText(fontName[fontList.getSelectedIndex()]);  
                    fontText.selectAll();  
                    Font sampleFont1=new Font(fontText.getText(),style[styleList.getSelectedIndex()],Integer.parseInt(sizeText.getText()));  
                    sample.setFont(sampleFont1);  
                }  
            });  
            styleList.addListSelectionListener(new ListSelectionListener()  
            {   public void valueChanged(ListSelectionEvent event)  
                {   int s=style[styleList.getSelectedIndex()];  
                    styleText.setText(fontStyle[s]);  
                    styleText.selectAll();  
                    Font sampleFont2=new Font(fontText.getText(),style[styleList.getSelectedIndex()],Integer.parseInt(sizeText.getText()));  
                    sample.setFont(sampleFont2);  
                }  
            });  
            sizeList.addListSelectionListener(new ListSelectionListener()  
            {   public void valueChanged(ListSelectionEvent event)  
                {   sizeText.setText(fontSize[sizeList.getSelectedIndex()]);  
                    sizeText.selectAll();     
                    Font sampleFont3=new Font(fontText.getText(),style[styleList.getSelectedIndex()],Integer.parseInt(sizeText.getText()));  
                    sample.setFont(sampleFont3);  
                }  
            });  
            okButton.addActionListener(new ActionListener()  
            {   public void actionPerformed(ActionEvent e)  
                {   Font okFont=new Font(fontText.getText(),style[styleList.getSelectedIndex()],Integer.parseInt(sizeText.getText()));  
                    area.setFont(okFont);  
                    fontDialog.dispose();  
                }  
            });  
            JPanel samplePanel=new JPanel();  
            samplePanel.setBorder(BorderFactory.createTitledBorder("示例"));    
            samplePanel.add(sample);  
            JPanel panel1=new JPanel();  
            JPanel panel2=new JPanel();  
            JPanel panel3=new JPanel();  
            
            panel1.add(fontLabel);
            panel1.add(styleLabel);
            panel1.add(sizeLabel);
            
            panel2.add(fontText);  
            panel2.add(styleText);  
            panel2.add(sizeText);  
              
            panel3.add(new JScrollPane(fontList));
            panel3.add(new JScrollPane(styleList));  
            panel3.add(new JScrollPane(sizeList));  
            
            con.add(panel1);  
            con.add(panel2);  
            con.add(panel3);  
            con.add(samplePanel);  
            con.add(okButton);
            con.add(cancel);  
            fontDialog.setSize(550,440);  
            fontDialog.setLocation(600,200);  
            fontDialog.setResizable(false);  
            fontDialog.setVisible(true);  
        }  
        
        //放大功能
        public void big() {
        	bigItem.addActionListener(new ActionListener() {
        		public void actionPerformed(ActionEvent e) {
        		String name=area.getFont().getFontName();
        		int style=area.getFont().getStyle();
        		int size=area.getFont().getSize();
        		area.setFont(new Font(name,style,size+1));
        		}
        		});
        }
        //缩小功能
        public void small() {
        	smallItem.addActionListener(new ActionListener() {
        		public void actionPerformed(ActionEvent e) {
        		String name=area.getFont().getFontName();
        		int style=area.getFont().getStyle();
        		int size=area.getFont().getSize();
        		area.setFont(new Font(name,style,size-1));
        		}
        		});
        }
        //恢复默认功能
        public void former() {
        	defaultItem.addActionListener(new ActionListener() {
        		public void actionPerformed(ActionEvent e) {
        		String name=area.getFont().getFontName();
        		int style=area.getFont().getStyle();
        		int size=area.getFont().getSize();
        		area.setFont(new Font(name,style,12));
        		}
        		});
        }
        //查看帮助
       public void help() {
        	askHelpItem.addActionListener(new ActionListener() {
        		public void actionPerformed(ActionEvent e) {
        			Desktop desk=Desktop.getDesktop();
        			try {
        				URI uri = new URI("https://cn.bing.com/search?q=%E8%8E%B7%E5%8F%96%E6%9C%89%E5%85%B3+windows+10+%E4%B8%AD%E7%9A%84%E8%AE%B0%E4%BA%8B%E6%9C%AC%E7%9A%84%E5%B8%AE%E5%8A%A9&filters=guid:%224466414-zh-hans-dia%22%20lang:%22zh-hans%22&form=T00032&ocid=HelpPane-BingIA");
        			    desk.browse(uri);
        			}
        			catch (MalformedURLException e1) {
    					// TODO 自动生成的 catch 块
    					e1.printStackTrace();
    				}
        			catch (IOException e1) {
    					// TODO 自动生成的 catch 块
    					e1.printStackTrace();
    				} 
        			catch (URISyntaxException e1) {
    					// TODO 自动生成的 catch 块
    					e1.printStackTrace();
    				}
        		}
        		});
        }
        public void about() {
        	JOptionPane.showMessageDialog(this,
    				"*********************************************\n" + " 编写者：呃叻yan \n"
    						+ " 编写时间：2021-06-09                           \n" + "    QQ：3033827669                \n"
    						+ " 有些功能未能实现，不足之处希望大家能提出意见，谢谢！  \n" + "*********************************************\n",
    				"记事本", JOptionPane.INFORMATION_MESSAGE);

   
        }
        
        
        
        
      
        //public void menuPerformed(MenuEvent e)  
        //{ checkMenuItemEnabled();//设置剪切、复制、粘贴、删除等功能的可用性  
        //}  
      

	

	// 按钮事件监听
	public void actionPerformed(ActionEvent e) {
		JMenuItem performed = (JMenuItem) e.getSource();
		if (performed == newItem) {
			new Window();
		} else if (performed == openItem) {
			chooser.showOpenDialog(null);// Dialog 会话
			file = chooser.getSelectedFile();
			try {
				fis = new FileInputStream(file);
				byte[] b = new byte[(int) file.length()];
				fis.read(b);
				area.append(new String(b));
				fis.close();
 
			} catch (FileNotFoundException e1) {
				e1.printStackTrace();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		} else if (performed == saveItem) {
			chooser.showSaveDialog(null);
			chooser.setDialogTitle("另存为");
			file = chooser.getSelectedFile();
			if (!file.exists()) {
				try {
					file.createNewFile();
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
			try {
				fos = new FileOutputStream(file);
				String text = area.getText();
				fos.write(text.getBytes());
				fos.close();
			} catch (FileNotFoundException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		} 
		else if (performed == saveAsItem) {
			chooser.showSaveDialog(null);
			chooser.setDialogTitle("另存为");
			file = chooser.getSelectedFile();
			if (!file.exists()) {
				try {
					file.createNewFile();
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
			try {
				fos = new FileOutputStream(file);
				String text = area.getText();
				fos.write(text.getBytes());
				fos.close();
			} catch (FileNotFoundException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		} 
		 //页面设置  
        else if(e.getSource()==setUpItem) { 
            area.requestFocus();  
            JOptionPane.showMessageDialog(this,"对不起，此功能尚未实现！更多请看http://pan.muyi.so","提示",JOptionPane.WARNING_MESSAGE);  
        }//页面设置结束 
		//打印  
        else if(e.getSource()==printItem) { 
            area.requestFocus();  
            JOptionPane.showMessageDialog(this,"对不起，此功能尚未实现！更多请看http://pan.muyi.so","提示",JOptionPane.WARNING_MESSAGE);  
        }//打印结束  
        //退出  
		else if (performed == closeItem) {
			//JOptionPane.showConfirmDialog(this,"确认退出","确认对话框",JOptionPane.YES_NO_OPTION ); 
			int op = JOptionPane.showConfirmDialog(this,"是否确认退出？？？？","确认对话框",JOptionPane.YES_NO_OPTION);
			if(op==JOptionPane.YES_OPTION)
				System.exit(1);
			
			else
				return;
			
		
		}
		
		
		//撤销  
        else if(e.getSource()==undoItem || e.getSource()==popupUndoItem) { 
            area.requestFocus();  
            if(undo.canUndo())  {
               try  
                {   undo.undo();  
                }  
                catch (CannotUndoException ex)  
                {   System.out.println("Unable to undo:" + ex);  
                    ex.printStackTrace();  
                }  
            }  
            if(!undo.canUndo())  {
                    undoItem.setEnabled(false);
                    popupUndoItem.setEnabled(false);
                }  
        }//撤销结束  
		//剪切功能
		else if(e.getSource()==cutItem || e.getSource()==popupCutItem) {
			area.requestFocus();
			String text=area.getSelectedText();
			StringSelection selection=new StringSelection(text);
			clipBoard.setContents(selection, null);
			area.replaceRange("", getSelectionStart(),area.getSelectionEnd());
			checkMenuItemEnabled();
		}
		//剪切结束
		
		//复制功能
		else if(e.getSource()==copyItem || e.getSource()==popupCopyItem) {
			area.requestFocus();
			String text=area.getSelectedText();
			StringSelection selection=new StringSelection(text);
			clipBoard.setContents(selection, null);
			checkMenuItemEnabled();
		}
		//粘贴功能
		else if(e.getSource()==pasteItem || e.getSource()==popupPasteItem) {
			area.requestFocus();
			Transferable contents=clipBoard.getContents(this);
			if(contents==null)return;
			String text="";
			try {
				text=(String)contents.getTransferData(DataFlavor.stringFlavor);
			}
			catch(Exception exception) {}
			area.replaceRange(text, area.getSelectionStart(), area.getSelectionEnd());	
			checkMenuItemEnabled();
		}
		//粘贴结束
		//删除
		else if(e.getSource()==deleteItem || e.getSource()==popupDeleteItem) {
			area.requestFocus();
			area.replaceRange("", area.getSelectionStart(), area.getSelectionEnd());
			checkMenuItemEnabled();
		}
		//删除结束
		//全选
		else if(e.getSource()==allItem || e.getSource()==popupAllItem) {
			area.selectAll();
		}
		//查找
		else if(e.getSource()==findItem) {
			area.requestFocus();
			find();
		}
			
		//查找下一个
		else if(e.getSource()==findNextItem) {
			area.requestFocus();
			find();
		}
		//替换
		else if(e.getSource()==replaceItem) {
			area.requestFocus();
			replace();
		}
		//转到
		 else if(e.getSource()==goItem)  
	        {   area.requestFocus();  
	            JOptionPane.showMessageDialog(this,"对不起，此功能尚未实现！更多请看http://pan.muyi.so","提示",JOptionPane.WARNING_MESSAGE);  
	        }
		//全选
		 else if(e.getSource()==allItem || e.getSource()==popupAllItem) {
			 area.selectAll();
		 }
		//时间日期
		 else if(e.getSource()==dateItem) {
			 area.requestFocus();
			 Calendar rightNow=Calendar.getInstance();
			 Date date=rightNow.getTime();
			 area.insert(date.toString(),area.getCaretPosition());
		 }
		//自动换行
		 else if(e.getSource()==wrapItem) {  //添加自动换行事件
			 if(wrapItem.getState())         //判断是否自动换行，是自动换行
				 area.setLineWrap(true);      //设置内容自动换行
			 else                             //格式菜单不勾选自动换行
				 area.setLineWrap(false);     //内容不自动换行
		 }
		//字体
		 else if(e.getSource()==fontItem) {
			 area.requestFocus();
			 font();
		 }
		//放大
		 else if(e.getSource()==bigItem) {
			 area.requestFocus();
			 big();
		 }
		//缩小
		 else if(e.getSource()==smallItem) {
			 area.requestFocus();
			 small();
		 }
		//恢复默认状态
		 else if(e.getSource()==defaultItem) {
			 area.requestFocus();
			 former();
		 }
		//状态栏
		 else if(e.getSource()==statusItem) {
			 if(statusItem.isSelected()) {
				 statusLabel.setVisible(true);
			     label.setVisible(true);
			     labelTime.setVisible(true);
			     labelCodeStyle.setVisible(true);
			 }
			 else {
				 statusLabel.setVisible(false);
			     label.setVisible(false);
			     labelTime.setVisible(false);
			     labelCodeStyle.setVisible(false);
			 }
		 }
		 
		//查看帮助
		 else if(e.getSource()==askHelpItem) {
			 area.requestFocus();
			 help();
		 }
		//发送反馈
		 else if(e.getSource()==feedbackItem) {
		 area.requestFocus();  
         JOptionPane.showMessageDialog(this,"对不起，此功能尚未实现！更多请看http://pan.muyi.so","提示",JOptionPane.WARNING_MESSAGE);  
		 }
		//关于记事本
		 else if(e.getSource()==aboutItem) {
			 area.requestFocus();
			 about();
		 }
		
		
	}
	
	
	
	
 
	

	private int getSelectionStart() {
		// TODO 自动生成的方法存根
        return 0;
	}

      @SuppressWarnings("unused")
	private StringBuffer StringBuffer(byte[] b) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void insertUpdate(DocumentEvent e) {
		// TODO 自动生成的方法存根
		
	}

	@Override
	public void removeUpdate(DocumentEvent e) {
		// TODO 自动生成的方法存根
		
	}

	@Override
	public void changedUpdate(DocumentEvent e) {
		// TODO 自动生成的方法存根
		
	}
 


//实现DocumentListener接口中的方法(与撤销操作有关)  
public void removeUpdate1(DocumentEvent e)  
{   undoItem.setEnabled(true);  
}  
public void insertUpdate1(DocumentEvent e)  
{   undoItem.setEnabled(true);  
}  
public void changedUpdate1(DocumentEvent e)  
{   undoItem.setEnabled(true);  
}//DocumentListener结束  

//实现接口UndoableEditListener的类UndoHandler(与撤销操作有关)  
class UndoHandler implements UndoableEditListener  
{   public void undoableEditHappened1(UndoableEditEvent uee)  
    {   undo.addEdit(uee.getEdit());  
    }

@Override
public void undoableEditHappened(UndoableEditEvent e) {
	// TODO 自动生成的方法存根
	
}  
}
}


